<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
          function setCookie( name , value , options ){
                 options = options || {};
                  
                 if(typeof options.expires === "number"){
                   var d = new Date();
                   d.setDate(d.getDate() + options.expires);
                 }
                 
                 return document.cookie = [
                       name + "=" + value,
                       typeof options.expires === "number" ? ";expires=" + d : "" ,
                       typeof options.path === "string" ? ";path=" + options.path : "",
                       typeof options.domain === "string" ? ";domain=" + options.domain : ""  
                 ].join("");
            }

            setCookie( "nihao" , "hello" , {
                  domain : "localhost"
            } )
    </script>
</body>
</html>